-- Leviathan (c) v.v.balashoff
local Class = require('leviathan/Class')

local MusicSystem = Class:derive('CoreMusicSystem')

function MusicSystem:new(domain)
    self.name = 'CoreMusicSystem'
    self.domain = domain
end

function MusicSystem:update(dt)
    local comps = self.domain.components['Audio']
    if comps then
        for i = 1, #comps do
            local comp = comps[i]
            local entity = comp.entity
            local playing = comp.audio:isPlaying()
            if not playing then
                -- delete stopped audio
                entity.domain:deleteEntity(entity)
            end
        end
    end
end

return MusicSystem
